﻿using Sunny.FrameDecoder;
using Sunny.Udp;
using Sunny.UI;
using System;
using System.Windows.Forms;

namespace Sunny.UDP.Demo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            //receiver.SetFrameDecoder(() => new FixedLengthFrameDecoder(10));
            receiver.OnReceive += Receiver_OnReceive1;
            receiver.Start();
        }

        private void Receiver_OnReceive1(object sender, UdpByteDataEventArgs e)
        {
            Console.WriteLine(e.IPEndPoint.ToString() + ": " + e.Value.ToHexString());
        }

        private void Receiver_OnReceive(object sender, IByteEventArgs e)
        {

        }

        UdpReceiver receiver = new UdpReceiver(6616);
        UdpSender client = new UdpSender(64 * 1024);

        private void button1_Click(object sender, EventArgs e)
        {
            //client.Bind(6000);
            //client.SetIPAndPort("192.168.31.255", 6616);
            //client.Send(Encoding.UTF8.GetBytes(textBox1.Text));
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //client.Bind(6001);
            //client.SetIPAndPort("192.168.31.255", 6616);
            //client.Send(Encoding.UTF8.GetBytes(textBox1.Text));
        }
    }
}
